<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #wp {
            width: 500px;
            margin: 100px;
        }
        
        select {
            margin-left: 20px;
        }
    </style>
</head>

<body>
    <div id="wp">
        <select name="" id="province">
            <option value="0">请选择</option>
        </select>省
        <select name="" id="city">
            <option value="0">请选择</option>
        </select>市
        <select name="" id="area">
            <option value="0">请选择</option>
        </select>区
    </div>




    <script src="js/city.js"></script>
    <!-- <script src="js/index.js"></script> -->
    <!-- <script src="js/demo.js"></script> -->
    <script>
        //获取数据
        let cityD;

        function getData(data, type) {
            type.innerHTML = '<option>请选择</option>'
            data.forEach(item => {
                let option = document.createElement("option");
                option.value = item.value;
                option.innerHTML = item.text;
                type.appendChild(option);
            })
        }
        getData(cityData3, province)

        province.onchange = function() {
            let val = this.value;
            cityData3.forEach(item => {
                if (item.value === val) {
                    cityD = item.children;
                    getData(item.children, city)
                }
            })
        }

        city.onchange = function() {
            let val = this.value;
            cityD.forEach(item => {
                if (item.value === val) {
                    getData(item.children, area)
                }
            })
        }
    </script>
</body>

</html>